package com.jxs.android.cmcc;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.jxs.android.cmcc.data.MenuInfo;
import com.jxs.android.cmcc.db.MenuHolder;
import com.jxs.android.weiget.MenuPageView;
import com.jxs.android.weiget.TopBar;

public class SubMain extends AbstractActivity {
	private ArrayList<MenuInfo> menuInfos = new ArrayList<MenuInfo>();

	private Context context;
	private MenuInfo superMenuInfo;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		context = this;
		if (null != getIntent() && null != getIntent().getExtras()) {
			superMenuInfo = (MenuInfo) getIntent().getExtras().getSerializable("menuInfo");
		}
		initTopBar(savedInstanceState, R.layout.bu_sub_main);

		if (null != superMenuInfo) {
			menuInfos = MenuHolder.getMenuInfos(superMenuInfo.getMenu_id(), MenuHolder.Keys.SUB_MENU_LEVEL);
		}

		MenuPageView menuPageView = (MenuPageView) findViewById(R.id.menu_page_view);
		menuPageView.setNumColumns(4);
		menuPageView.setMenuInfos(menuInfos);
		menuPageView.setItemClickListern(new MenuPageView.ItemClickListern() {

			@Override
			public void callBack(MenuInfo menuInfo) {
				Intent intent = new Intent(context, TableList.class);
				Bundle bundle = new Bundle();
				bundle.putSerializable("menuInfo", menuInfo);
				intent.putExtras(bundle);
				startActivity(intent);
			}
		});

	}

	@Override
	public void topBarLogic(TopBar topBar) {
		super.topBarLogic(topBar);
		topBar.hindBtn();
		initTopBarReturn(topBar);
		if (null != superMenuInfo) {
			topBar.setTitle(superMenuInfo.getMenu_name());
		}
	}

}
